local sk__qixing = fk.CreateSkill {

  name = "sk__qixing",

  tags = {},

}



sk__qixing:addEffect(fk.GameStart, {
  name = "sk__qixing",
  anim_type = "drawcard",
  derived_piles = "sk__godzhugeliang_star",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(sk__qixing.name) then
      return true
    end
  end,
  on_cost = function(self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(7, sk__qixing.name)
    if player.dead or player:isKongcheng() then return end
    local cards = room:askForCard(player, math.min(player:getHandcardNum(), 7), 999, false, sk__qixing.name, false, ".",
      "#sk__qixing-put")
    player:addToPile("sk__godzhugeliang_star", cards, false, sk__qixing.name, player.id)
  end,
})
sk__qixing:addEffect(fk.EventPhaseEnd, {
  name = "sk__qixing",
  anim_type = "drawcard",
  derived_piles = "sk__godzhugeliang_star",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(sk__qixing.name) then
      return target == player and player.phase == Player.Draw and not player:isKongcheng() and
          #player:getPile("sk__godzhugeliang_star") > 0
    end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, sk__qixing.name, data)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = room:askForArrangeCards(player, sk__qixing.name,
      { player:getPile("sk__godzhugeliang_star"), player:getCardIds("h"),
        "sk__godzhugeliang_star", "$Hand" }, "#sk__qixing-exchange", true)
    room:swapCardsWithPile(player, cards[1], cards[2], sk__qixing.name, "sk__godzhugeliang_star")
  end,
})

sk__qixing:addEffect("maxcards", {
  name = "#sk__qixing_maxcards",
  --sk__qixing,
  correct_func = function(self, player)
    if player:hasSkill(sk__qixing.name) then
      return #player:getPile("sk__godzhugeliang_star")
    else
      return 0
    end
  end,
})

return sk__qixing
